import {Injectable} from '@angular/core';
import {BaseHttpService} from '../base-http.service';
import {Observable} from 'rxjs';
import {PageInfo, SearchCommonVO} from '../../types';

export interface TestQuestionListModel {
  id: number;
  content: string;
  type: number;
  createTime: Date;
}

export interface TestQuestionModel {
  id?: number;
  type: number;
  analysis: string;
  content: string;
  difficultyGrade: number;
  pictureUrl: string;
  questionBlanks: number[];
  questionOptionDtos?: QuestionOptionDtos[];
  questionOptions?: QuestionOptions[];
}

export interface QuestionOptionDtos {
  answerFlag: boolean;
  content: string;
  pictureUrl: string;
}

export interface QuestionOptions {
  answerFlag: boolean;
  content: string;
  pictureUrl: string;
  id: number;
  sort?: null;
  questionId: number;
  createTime?: Date;
  updateTime?: Date;
}

/*题库下拉列表*/
export interface QuestionBankSelectList {
  id: number;
  name: string;
  remark?: string;
  radio?: Date;
  judge?: string;
  createTime?: Date;
}

@Injectable({
  providedIn: 'root'
})


export class TestQuestionService {

  constructor(public http: BaseHttpService) {
  }

  /*获取题库列表数据*/
  public getQuestionBankSelectList(param: SearchCommonVO<any>): Observable<PageInfo<QuestionBankSelectList>> {
    return this.http.post('/question-bank', param);
  }

  /*获取试题库列表数据*/
  public getTestQuestionList(param: SearchCommonVO<any>): Observable<PageInfo<TestQuestionListModel>> {
    return this.http.post('/question', param);
  }

  /*新增试题库名称*/
  public addTestQuestion(param: TestQuestionModel): Observable<TestQuestionModel> {
    return this.http.post('/insert-question', param, {needSuccessInfo: true});
  }

  /*编辑试题库信息*/
  public editTestQuestion(param: TestQuestionModel): Observable<TestQuestionModel> {
    return this.http.put('/question', param, {needSuccessInfo: true});
  }


  /*试题详情*/
  public getTestQuestionDetail(id: number): Observable<TestQuestionModel> {
    return this.http.get(`/question/${id}`);
  }

  /*删除试题*/
  public delTestQuestion(idArray: number[]): Observable<void> {
    return this.http.post('/del-question/', {ids: idArray}, {needSuccessInfo: true});
  }
}
